Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
Prototype as "just a plain object"

I always thought that a prototype had some magic around it, but it seems that a prototype is actually just an object attached to a function. As an example:

function someMethod() {};

function Person(name) {
    Object.assign(this, {name});
}
Person.prototype.number = 4;
Person.prototype.letter = "a";
Person.prototype.method = someMethod;

let obj = {
    number:4, 
    letter:'a',
    method: someMethod
};

console.log(`\
${Object.entries(Person.prototype).toString()}
${Object.entries(obj).toString()}
${Object.entries(Person.prototype).toString() == Object.entries(obj).toString()}\
`);

Is that more or less a correct understanding of what the prototype is? Or does any other machinery go on behind the scenes that the obj in the above example does not include?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

A .prototype object is indeed just an ordinary object. It is used in prototype chains like any other object can be used in them.

The only "magic" behind implicitly created .prototype objects on functions is that they have a non-enumerable .constructor property that points back to the function.

function Person() {}
let obj = {};

console.log(Object.hasOwn(obj, 'constructor'));
console.log(Object.hasOwn(Person.prototype, 'constructor'));

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda